home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 17 / CU Amiga Magazine's Super CD-ROM 17 (1997)(EMAP Images)(GB)[!][issue 1997-12].iso / CUCD / Graphics / RTGmaster / demos / network / P2PClient.c < prev    next >
C/C++ Source or Header  |  1997-09-26  |  2KB  |  67 lines

  1. #include <clib/exec_protos.h>
  2. #include <pragmas/exec_pragmas.h>
  3. #include <stdio.h>
  4. #include <strings.h>
  5. #include <clib/rtgextra_protos.h>
  6. #include <pragmas/rtgextra_pragmas.h>
  7. #include <rtgmaster/rtgtcpip.h>
  8. #define UDPDemo 1
  9.  
  10. // set UDPDemo to 0 if you want to
  11. // compile this demo to use TCP instead
  12. // of UDP
  13.  
  14. struct Library *SocketBase=0;
  15. struct Library *RTGExtraBase=0;
  16.  
  17. void makeservaddr(struct sockaddr_in *address, char *host, int port);
  18. struct RTG_Socket *LIBOpenClient(char *host, struct Library *SBase, int port, int mode, int protocol);
  19. struct RTG_Socket rs;
  20.  
  21. void main()
  22. {
  23.  struct RTG_Socket *s;
  24.  if (RTGExtraBase=OpenLibrary("rtgextra.library",0))
  25.  {
  26.   if (SocketBase=OpenLibrary("bsdsocket.library",4))
  27.   {
  28.    int i;
  29.    long mode=1;
  30.    char buf[1024];
  31.    char *strings[]={"Nur","ein","Test",NULL};
  32.  
  33. #ifndef UDPDemo
  34.    s=OpenClient(SocketBase,"194.55.101.26",3056,SOCK_STREAM,0);
  35. #else
  36.    s=OpenClient(SocketBase,"194.55.101.26",3056,SOCK_DGRAM,0);
  37. #endif
  38.  
  39.    RtgIoctl(SocketBase,s,&mode);
  40.    for (i=0;strings[i]!=NULL;i++)
  41.    {
  42.     struct sockaddr_in *si;
  43.  
  44.     // Note about the following 2 lines : GetUDPName returns
  45.     // 0 for TCP connections, so this code will work for
  46.     // TCP *and* UDP !!!
  47.  
  48.     si=GetUDPName(SocketBase,s);
  49.  
  50.     do {} while (RtgSend(SocketBase,s,(strings[i]),si,strlen(strings[i])+1)<=0);
  51.     do {} while (RtgRecv(SocketBase,s,buf,si,1024)<=0);
  52.  
  53. #ifndef UDPDemo
  54. #else
  55.        printf("Message from : %s",RtgInAdr(SocketBase,si));
  56. #endif
  57.  
  58.     printf("%s\n",buf);
  59.    }
  60.    CloseClient(SocketBase,s);
  61.    CloseLibrary(SocketBase);
  62.    CloseLibrary(RTGExtraBase);
  63.   }
  64.  }
  65. }
  66.  
  67.